package com.liupengyuan.system.login.action;



import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.liupengyuan.framework.web.struts2.BaseAction;
import com.liupengyuan.system.login.service.impl.LoginServiceImpl;
import com.liupengyuan.system.user.model.User;
import com.liupengyuan.system.user.service.UserService;
import com.opensymphony.xwork2.ModelDriven;
@Controller("loginAction")
@Scope("prototype")
public class LoginAction extends BaseAction implements ModelDriven<User>{

	private static final long serialVersionUID = -5188457976857928890L;

	@Autowired
	private LoginServiceImpl loginService;
	@Autowired
	private UserService userService;
	private User logUser;
	
	public String ids;
	
	public String login(){
		String dir = ServletActionContext.getRequest().getRealPath("\\");
		System.out.println(dir);
		if(StringUtils.isEmpty(logUser.getUsername()) || StringUtils.isEmpty(logUser.getPassword())){
			return NONE;
		}
		User loginUser = userService.login(logUser);
		if(loginUser == null){
			return NONE;
		}
		if(logUser.getUsername().equals(loginUser.getUsername())){
			getRequest().getSession().setAttribute("current", loginUser);
			return SUCCESS;
		}else{
			return ERROR;
		}
	}
	
	public User getModel() {
		logUser = new User();
		return logUser;
	}
	
	
	
}
